﻿Imports Microsoft.Win32
Imports System.Text
Imports SysPadDB.Data

Module publicModule
    Public FolderPad As New frmFolderPad
    Public TrayPad As New frmTrayPad

    Public AppPath As String = System.AppDomain.CurrentDomain.BaseDirectory
    Public savePath As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\Syspad\"

    Public wVersion As WindowsVersion
    Dim vi As VersionInfo

    Public TrayPadHasOpened As Boolean = False

    Public Structure WindowsVersion
        Dim versionNumberFull As String
        Dim versionNumberBase As String
        Dim versionName As String
    End Structure

    Public Sub GetWindowsVersion()
        Dim versionString As String = Environment.OSVersion.Version.ToString
        Dim versionBase As String() = versionString.Split(".")
        With wVersion
            .versionNumberFull = versionString
            .versionNumberBase = versionBase(0)
            Select Case versionBase(0)
                Case 5
                    .versionName = "XP"
                Case 6
                    .versionName = "Vista"
                Case 7
                    .versionName = "Seven"
            End Select
        End With
    End Sub

    Public Sub GetLatestVersionInfo()
        If IsConnectionAvailable() Then
            vi = GetVersionInformation()
            If vi.user_version <> vi.db_version Then
                MessageBox.Show("There is a new version of SysPad!" & vbNewLine & "Click on 'Updates' from the System Tray to download the new version.", "Version Check", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        End If
    End Sub

    Public Function ExistsNotepad() As Boolean
        Dim regShell As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\App Paths\notepad++.exe", False)
        If regShell Is Nothing Then
            TrayPad.mnuExportToNP.Enabled = False
            TrayPad.mnuNotePad.Enabled = False
            Return False
        Else
            TrayPad.mnuExportToNP.Enabled = True
            TrayPad.mnuNotePad.Enabled = True
            Return True
        End If
    End Function

    Public Function ExistsAltap() As Boolean
        With My.Settings
            If .ExplorerLocation <> "" And Not System.IO.File.Exists(.ExplorerLocation & "\salamand.exe") = True Then
                .ExplorerLocation = ""
                .AltapIconColor = 0
                .AltapTitlebarPrefix = "SysPad"
                .AltapWindow = 0
                .ExplorerDefault = 0
                .ExplorerShift = 0
                MessageBox.Show("It seems your Altap Salamander installation no longer exists, has been misplaced or has been altered." & vbNewLine & "All data related to Altap Salamander has been reset to their defaults.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
                Return False
            Else
                Return True
            End If
        End With
    End Function
End Module
